import 'package:guochaoapp/model/sku_entity.dart';

skuEntityFromJson(SkuEntity data, Map<String, dynamic> json) {
	if (json['success'] != null) {
		data.success = json['success'];
	}
	if (json['msg'] != null) {
		data.msg = json['msg'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'] is String
				? int.tryParse(json['code'])
				: json['code'].toInt();
	}
	if (json['data'] != null) {
		data.data = new SkuData().fromJson(json['data']);
	}
	if (json['sign'] != null) {
		data.sign = json['sign'];
	}
	return data;
}

Map<String, dynamic> skuEntityToJson(SkuEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['success'] = entity.success;
	data['msg'] = entity.msg;
	data['code'] = entity.code;
	if (entity.data != null) {
		data['data'] = entity.data.toJson();
	}
	data['sign'] = entity.sign;
	return data;
}

skuDataFromJson(SkuData data, Map<String, dynamic> json) {
	if (json['skuList'] != null) {
		data.skuList = new List<SkuDataSkuList>();
		(json['skuList'] as List).forEach((v) {
			data.skuList.add(new SkuDataSkuList().fromJson(v));
		});
	}
	return data;
}

Map<String, dynamic> skuDataToJson(SkuData entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	if (entity.skuList != null) {
		data['skuList'] =  entity.skuList.map((v) => v.toJson()).toList();
	}
	return data;
}

skuDataSkuListFromJson(SkuDataSkuList data, Map<String, dynamic> json) {
	if (json['skuId'] != null) {
		data.skuId = json['skuId'] is String
				? int.tryParse(json['skuId'])
				: json['skuId'].toInt();
	}
	if (json['spuId'] != null) {
		data.spuId = json['spuId'] is String
				? int.tryParse(json['spuId'])
				: json['spuId'].toInt();
	}
	if (json['categoryName'] != null) {
		data.categoryName = json['categoryName'].toString();
	}
	if (json['skuSpec'] != null) {
		data.skuSpec = json['skuSpec'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? double.tryParse(json['price'])
				: json['price'].toDouble();
	}
	if (json['unit'] != null) {
		data.unit = json['unit'].toString();
	}
	if (json['mallTitle'] != null) {
		data.mallTitle = json['mallTitle'].toString();
	}
	if (json['mallLogo'] != null) {
		data.mallLogo = json['mallLogo'].toString();
	}
	if (json['brandId'] != null) {
		data.brandId = json['brandId'] is String
				? int.tryParse(json['brandId'])
				: json['brandId'].toInt();
	}
	if (json['brandName'] != null) {
		data.brandName = json['brandName'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'];
	}
	if (json['picUrlList'] != null) {
		data.picUrlList = json['picUrlList'];
	}
	if (json['stock'] != null) {
		data.stock = json['stock'] is String
				? int.tryParse(json['stock'])
				: json['stock'].toInt();
	}
	if (json['buyLimit'] != null) {
		data.buyLimit = json['buyLimit'] is String
				? int.tryParse(json['buyLimit'])
				: json['buyLimit'].toInt();
	}
	return data;
}

Map<String, dynamic> skuDataSkuListToJson(SkuDataSkuList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['skuId'] = entity.skuId;
	data['spuId'] = entity.spuId;
	data['categoryName'] = entity.categoryName;
	data['skuSpec'] = entity.skuSpec;
	data['price'] = entity.price;
	data['unit'] = entity.unit;
	data['mallTitle'] = entity.mallTitle;
	data['mallLogo'] = entity.mallLogo;
	data['brandId'] = entity.brandId;
	data['brandName'] = entity.brandName;
	data['description'] = entity.description;
	data['picUrlList'] = entity.picUrlList;
	data['stock'] = entity.stock;
	data['buyLimit'] = entity.buyLimit;
	return data;
}